package com.goods.controller.business;

import com.goods.business.service.SupplierService;
import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/business/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    //获取用户列表
    @GetMapping("/findSupplierList")
    public ResponseBean<PageVO<SupplierVO>> findSupplierList(@RequestParam(defaultValue = "1") Integer pageNum,
                                                             @RequestParam(defaultValue = "10") Integer pageSize,
                                                             String name,
                                                             String contact,
                                                             String address){

        PageVO<SupplierVO> pageVO = supplierService.findSupplierList(pageNum,pageSize,name,contact,address);
        return ResponseBean.success(pageVO);
    }

    //添加物资来源
    @PostMapping("/add")
    public ResponseBean addSupplier(@RequestBody Supplier supplier){
        supplierService.addSupplier(supplier);
        return ResponseBean.success();
    }

    //编辑物资来源
    @GetMapping("/edit/{id}")
    public ResponseBean editSupplier(@PathVariable Long id){
        Supplier supplier = supplierService.editSupplier(id);
        return ResponseBean.success(supplier);
    }

    //更新物资来源
    @PutMapping("/update/{id}")
    public ResponseBean updateSupplier(@PathVariable Long id,
                                       @RequestBody Supplier supplier){
        supplierService.updateSupplier(supplier);
        return ResponseBean.success();
    }

    //删除物资来源
    @DeleteMapping("/delete/{id}")
    public ResponseBean deleteSupplier(@PathVariable Long id){
        supplierService.deleteSupplier(id);
        return ResponseBean.success();
    }

    //获取所有用户来源
    @GetMapping("/findAll")
    public ResponseBean findAll(){
        List<Supplier> supplierList = supplierService.findAll();
        return ResponseBean.success(supplierList);
    }
}
